# Maintainer: David Runge <dvzrv@archlinux.org>
# Maintainer: Jonas Witschel <diabonas@archlinux.org>

pkgname=shim
pkgver=15.7
_commit=46f7220ff61dc5dea95273ccb595de31b2b3bf9e  # refs/tags/15.7
pkgrel=1
pkgdesc="EFI preloader (unsigned EFI binaries)"
arch=(any)
url="https://github.com/rhboot/shim"
license=(BSD)
makedepends=(git)
checkdepends=(efivar xxd)
source=(
  git+https://github.com/rhboot/shim.git#tag=$_commit?signed
  rhboot-gnu-efi::git+https://github.com/rhboot/gnu-efi.git
)
md5sums=('SKIP'
         'SKIP')
validpgpkeys=(
  B00B48BC731AA8840FED9FB0EED266B70F4FEF10  # Peter Jones <pjones@redhat.com>
  039A9CEA19DE9508C36875AA2532F9176A95A442  # Robbie Harwood (work) <rharwood@fedoraproject.org>
)

pkgver() {
  cd $pkgname
  git describe | sed 's/\([^-]*-\)g/r\1/;s/-/./g'
}

prepare() {
  cd $pkgname
  git submodule init
  git config submodule.gnu-efi.url "$srcdir/rhboot-gnu-efi"
  git -c protocol.file.allow=always submodule update

  # -Werror, not even once
  sed -e 's/-Werror\b//g' -i Makefile Make.defaults
}

build() {
  cd $pkgname
  # TODO: evaluate setting DEFAULT_LOADER to e.g. loader.efi:
  # this would require changing grub's default, but would allow us to unify
  make EFIDIR=ARCH
}

check() {
  cd $pkgname
  make test
}

package() {
  cd $pkgname
  make DATATARGETDIR="/usr/share/$pkgname" DESTDIR="$pkgdir/" install-as-data
  install -vDm 644 COPYRIGHT -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 {BUILDING,README.{md,fallback,tpm},TODO} -t "$pkgdir/usr/share/doc/$pkgname/"
}
